Jak zjistit nazev domeny?

Otázka od: pilifs

17. 9. 2002 7:25

Hello Delphi,

  potreboval bych zjistit jmeno domeny ve ktere se nachazim. Muzete
  nekdo poradit?

Diky.

D5 Ent, W2000, MSSQL2000

--
Best regards,
 pilifs mailto:pilifs@seznam.cz

Odpovedá: Ondrej Kelle

17. 9. 2002 15:08

> potreboval bych zjistit jmeno domeny ve ktere se nachazim. Muzete
> nekdo poradit?

const
  netapi32 = 'netapi32.dll';

type
  PWkstaUserInfo1 = ^TWkstaUserInfo1;
  TWkstaUserInfo1 = packed record
    wkui1_username: PWideChar;
    wkui1_logon_domain: PWideChar;
    wkui1_oth_domains: PWideChar;
    wkui1_logon_server: PWideChar;
  end;
  PWkstaInfo = ^TWkstaInfo;
  TWkstaInfo = packed record
     wki100_platform_id: DWORD;
     wki100_computername: PWideChar;
     wki100_langroup: PWideChar;
     wki100_ver_major: DWORD;
     wki100_ver_minor: DWORD;
  end;

function NetWkstaUserGetInfo(reserved: PWideChar; level: DWORD; var bufptr:
Pointer): Integer; stdcall;
  external netapi32 name 'NetWkstaUserGetInfo';
function NetWkstaGetInfo(servername: PWideChar; level: DWord; var bufprt:
Pointer): integer; stdcall;
 external 'netapi32.dll' name 'NetWkstaGetInfo';
function NetApiBufferFree(Buffer : Pointer) : Integer; stdcall;
  external netapi32 name 'NetApiBufferFree';

procedure TForm1.Button1Click(Sender: TObject);
var
  P: Pointer;
begin
  NetWkstaUserGetInfo(nil, 1, P);
  try
    with PWkstaUserInfo1(P)^ do
      
ShowMessage(Format('username: %s'#13'logon_domain: %s'#13'oth_domains:
%s'#13'logon_server: %s',
        [wkui1_username, wkui1_logon_domain, wkui1_oth_domains,
wkui1_logon_server]));
  finally
    NetApiBufferFree(P);
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  P: Pointer;
begin
  NetWkstaGetInfo(nil, 100, P);
  try
    with PWkstaInfo(P)^ do
      
ShowMessage(Format('platform_id: %d'#13'computername: %s'#13'langroup:
%s'#13'ver: %d.%d',
        [wki100_platform_id, wki100_computername, wki100_langroup,
wki100_ver_major, wki100_ver_minor]));
  finally
    NetApiBufferFree(P);
  end;
end;

HTH
TOndrej

Odpovedá: Ondrej Kelle

18. 9. 2002 14:32

> a nevite nekdo jak tohle zjistit u w9x ?

NetWkstaGetInfo:
http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q155698&;

netapi.dll je 16-bitova, takze pri volani z 32-bitoveho kodu musis pouzit
thunking:
http://www.thedelphimagazine.com/samples/thunk/thunk95.htm

HTH
TOndrej